import java.util.Scanner;
public class Visitor {
    public String name;
    public int age;

    Scanner input = new Scanner(System.in);

    //购买门票的方法
    public void buyTicket() {
        String str;
        do {
            System.out.print("请输入姓名：");
            this.name = input.next();
            System.out.print("请输入年龄：");
            this.age = input.nextInt();
            if (this.age >= 18 && this.age <= 60) {
                System.out.println(this.name + "的年龄为：" + this.age + ",门票20元");
            }
            if (this.age > 60 || this.age < 18) {
                System.out.println(this.name + "的年龄为：" + this.age + ",门票免费");
            }
            System.out.print("是否继续？(输入y：继续，输入其它字符退出):");
            str = input.next();
        } while ("y".equalsIgnoreCase(str));
        System.out.println("感谢您的使用，欢迎下次光临！");
    }

    public static void main(String[] args) {
        Visitor visitor = new Visitor();
        visitor.buyTicket();
    }
}

